$('#MC_Subscription_Set_Form').ready(function()
{
	/**
	* 获取元素
	*/
	var form=this;
	var button_submit=$('#MC_Subscription_Set_Submit');
	var button_reset=$('#MC_Subscription_Set_Reset');
	var ac=$('#AlertContainer');
			
	//获取元素-船舶
	var shipyard=$('#Shipyard');
	var shipyard_conjuncture=$('#Shipyard_Conjuncture');
	var shipyard_trends=$('#Shipyard_Trends');
	var shipyard_ordersheet=$('#Shipyard_Ordersheet');
	var shipyard_analysis=$('#Shipyard_Analysis');	
	
	//获取元素-船配
	var ancillary=$('#Ancillary');
	var ancillary_news=$('#Ancillary_News');
	var ancillary_company=$('#Ancillary_Company');
	var ancillary_ordersheet=$('#Ancillary_Ordersheet');
	var ancillary_steels=$('#Ancillary_Steels');
	
	//获取元素-船运
	var shipping=$('#Shipping');
	var shipping_market=$('#Shipping_Market');
	var shipping_trends=$('#Shipping_Trends');
	
	//获取元素-海工
	var maritimeworks=$('#Maritimeworks');
	var maritimeworks_trends=$('#Maritimeworks_Trends');
	var maritimeworks_ordersheet=$('#Maritimeworks_Ordersheet');

	//获取元素-数据
	var data=$('#Data');
	var data_new=$('#Data_New');
	var data_scrap=$('#Data_Scrap');
	var data_shipping=$('#Data_Shipping');
	var data_steels=$('#Data_Steels');
	var data_second=$('#Data_Second');
	var data_rent=$('#Data_Rent');	
	
	//获取元素-融资
	var finacing=$('#Finacing');
	var finacing_policy=$('#Finacing_Policy');
	var finacing_cooperation=$('#Finacing_Cooperation');
	var finacing_trends=$('#Finacing_Trends');
	var finacing_ipo=$('#Finacing_IPO');
	
	//获取元素-船型
	var shiptype=$('#ShipType');
	
	//获取元素-政策法规
	var law=$('#Law');
	
	//获取元素-技术
	var technology=$('#Technology');
	
	//获取元素-船配标准
	var standard=$('#Standard');
	
	//获取元素-专题
	var topic=$('#Topic');	
	
	//获取元素-访谈
	var interview=$('#Interview');		
	
	//获取元素-观察
	var observe=$('#Observe');		

	/**
	* 初始化控件
	*/
	var statistics=$('#MC_Subscription_Statistics').val().split('|');
	statistics.pop();
	for(var i=0;i<statistics.length;i++)
	{
		var tmp=statistics[i].split(':');
		var id=tmp[0].toLowerCase();
		var value=tmp[1];
		if(value=='1')
		{
			//每一个选项
			eval(id+".attr('checked',true);");
			//判断大项-船舶
			var tmp=id.split('_')[0];
			if(tmp=='shipyard'){
				shipyard.attr('checked',true);
			}
			//判断大项-船配
			if(tmp=='ancillary'){
				ancillary.attr('checked',true);
			}
			//判断大项-航运
			if(tmp=='shipping'){
				shipping.attr('checked',true);
			}
			//判断大项-海工
			if(tmp=='maritimeworks'){
				maritimeworks.attr('checked',true);
			}						
			//判断大项-融资
			if(tmp=='finacing'){
				finacing.attr('checked',true);
			}			
			//判断大项-数据
			if(tmp=='data'){
				data.attr('checked',true);
			}
		}
	}

	/**
	* 事件绑定-提交按钮
	*/
	button_submit.click(function()
	{
		var formData={};
		//数据-船舶
		if(shipyard_conjuncture.attr('checked')){
			formData['Shipyard_Conjuncture']=shipyard_conjuncture.val();
		}
		if(shipyard_trends.attr('checked')){
			formData['Shipyard_Trends']=shipyard_trends.val();
		}
		if(shipyard_ordersheet.attr('checked')){
			formData['Shipyard_Ordersheet']=shipyard_ordersheet.val();
		}
		if(shipyard_analysis.attr('checked')){
			formData['Shipyard_Analysis']=shipyard_analysis.val();
		}		
		//数据-船配
		if(ancillary_news.attr('checked')){
			formData['Ancillary_News']=ancillary_news.val();
		}
		if(ancillary_company.attr('checked')){
			formData['Ancillary_Company']=ancillary_company.val();
		}
		if(ancillary_ordersheet.attr('checked')){
			formData['Ancillary_Ordersheet']=ancillary_ordersheet.val();
		}
		if(ancillary_steels.attr('checked')){
			formData['Ancillary_Steels']=ancillary_steels.val();
		}
		//数据-航运
		if(shipping_market.attr('checked')){
			formData['Shipping_Market']=shipping_market.val();
		}
		if(shipping_trends.attr('checked')){
			formData['Shipping_Trends']=shipping_trends.val();
		}
		//数据-海工
		if(maritimeworks_trends.attr('checked')){
			formData['Maritimeworks_Trends']=maritimeworks_trends.val();
		}
		if(maritimeworks_ordersheet.attr('checked')){
			formData['Maritimeworks_Ordersheet']=maritimeworks_ordersheet.val();
		}
		//数据-数据
		if(data_new.attr('checked')){
			formData['Data_New']=data_new.val();
		}
		if(data_scrap.attr('checked')){
			formData['Data_Scrap']=data_scrap.val();
		}
		if(data_shipping.attr('checked')){
			formData['Data_Shipping']=data_shipping.val();
		}
		if(data_steels.attr('checked')){
			formData['Data_Steels']=data_steels.val();
		}
		if(data_second.attr('checked')){
			formData['Data_Second']=data_second.val();
		}	
		if(data_rent.attr('checked')){
			formData['Data_Rent']=data_rent.val();
		}
		//数据-融资
		if(finacing_policy.attr('checked')){
			formData['Finacing_Policy']=finacing_policy.val();
		}
		if(finacing_cooperation.attr('checked')){
			formData['Finacing_Cooperation']=finacing_cooperation.val();
		}
		if(finacing_trends.attr('checked')){
			formData['Finacing_Trends']=finacing_trends.val();
		}
		if(finacing_ipo.attr('checked')){
			formData['Finacing_IPO']=finacing_ipo.val();
		}
		//数据-船型
		if(shiptype.attr('checked')){
			formData['ShipType']=shiptype.val();
		}				
		//数据-政策法规
		if(law.attr('checked')){
			formData['Law']=law.val();
		}
		//数据-技术
		if(technology.attr('checked')){
			formData['Technology']=technology.val();
		}
		//数据-船配标准
		if(standard.attr('checked')){
			formData['Standard']=standard.val();
		}
		//数据-专题
		if(topic.attr('checked')){
			formData['Topic']=topic.val();
		}	
		//数据-访谈
		if(interview.attr('checked')){
			formData['Interview']=interview.val();
		}	
		//数据-观察
		if(observe.attr('checked')){
			formData['Observe']=observe.val();
		}
		
		//验证数据
		 /*var count=0;
		 for(var tmp in formData){
			 count++;
		 }
		 if(count==0){
			 ac.show();
			 ac.html('请选择订阅的资讯类别');
			return false; 
		 }*/
		
		//封锁按钮
		button_submit.attr('disabled',true);
		button_reset.attr('disabled',true);
		ac.html('正在更新配置，请稍候...');
		ac.show();
		
		//提交数据
		$.post($('#MC_Subscription_Set_Form').attr('action'),formData,function($data)
		{
			if($data=='Succeed'){
				callac('设置成功。');
			}
			else{
				callac('设置失败。');
			}
			function callac($text)
			{
				window.setTimeout(function(){
					ac.html($text);						   
					//解锁按钮
					button_submit.attr('disabled',false);
					button_reset.attr('disabled',false);						
				},1000);			
			}					
		});
		return false;
	});	
	
	/**
	* 事件绑定-重置按钮
	*/	
	button_reset.click(function()
	{
		form[0].reset();
		return false;
	});
	
	/**
	* 事件绑定-船舶
	*/	
	shipyard.click(function()
	{
		if(this.checked)
		{
			shipyard_conjuncture.attr('checked','checked');
			shipyard_trends.attr('checked','checked');
			shipyard_ordersheet.attr('checked','checked');
			shipyard_analysis.attr('checked','checked');
		}
		else
		{
			shipyard_conjuncture.attr('checked',false);
			shipyard_trends.attr('checked',false);
			shipyard_ordersheet.attr('checked',false);
			shipyard_analysis.attr('checked',false);		
		}
	});	
	
	//事件绑定-子类
	shipyard.funcs={};
	shipyard.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			shipyard.attr('checked','checked');
		}
		else
		{
			var tmp=shipyard_conjuncture.attr('checked')!='checked'&&shipyard_trends.attr('checked')!='checked';
				tmp=tmp&&shipyard_ordersheet.attr('checked')!='checked'&&shipyard_analysis.attr('checked')!='checked';
			if(tmp){
				shipyard.attr('checked',false);
			}
		}
	};
	shipyard_conjuncture.click(function(){shipyard.funcs.callback(shipyard_conjuncture)});
	shipyard_trends.click(function(){shipyard.funcs.callback(shipyard_trends)});
	shipyard_ordersheet.click(function(){shipyard.funcs.callback(shipyard_ordersheet)});
	shipyard_analysis.click(function(){shipyard.funcs.callback(shipyard_analysis)});	
	
	/**
	* 事件绑定-船配
	*/		
	ancillary.click(function()
	{
		if(this.checked)
		{
			ancillary_news.attr('checked',true);
			ancillary_company.attr('checked',true);
			ancillary_ordersheet.attr('checked',true);
			ancillary_steels.attr('checked',true);
		}
		else
		{
			ancillary_news.attr('checked',false);
			ancillary_company.attr('checked',false);
			ancillary_ordersheet.attr('checked',false);
			ancillary_steels.attr('checked',false);	
		}		
	});
	
	//事件绑定-子类
	ancillary.funcs={};
	ancillary.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			ancillary.attr('checked','checked');
		}
		else
		{
			var tmp=ancillary_news.attr('checked')!='checked'&&ancillary_company.attr('checked')!='checked';
				tmp=tmp&&ancillary_ordersheet.attr('checked')!='checked'&&ancillary_steels.attr('checked')!='checked';
			if(tmp){
				ancillary.attr('checked',false);
			}
		}
	};
	ancillary_news.click(function(){ancillary.funcs.callback(ancillary_news)});
	ancillary_company.click(function(){ancillary.funcs.callback(ancillary_company)});
	ancillary_ordersheet.click(function(){ancillary.funcs.callback(ancillary_ordersheet)});
	ancillary_steels.click(function(){ancillary.funcs.callback(ancillary_steels)});
	
	/**
	* 事件绑定-船运
	*/		
	shipping.click(function()
	{
		if(this.checked)
		{
			shipping_market.attr('checked',true);
			shipping_trends.attr('checked',true);
		}
		else
		{
			shipping_market.attr('checked',false);
			shipping_trends.attr('checked',false);
		}		
	});
	
	//事件绑定-子类
	shipping.funcs={};
	shipping.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			shipping.attr('checked','checked');
		}
		else
		{
			var tmp=shipping_market.attr('checked')!='checked'&&shipping_trends.attr('checked')!='checked';
			if(tmp){
				shipping.attr('checked',false);
			}
		}
	};
	shipping_market.click(function(){shipping.funcs.callback(shipping_market)});
	shipping_trends.click(function(){shipping.funcs.callback(shipping_trends)});	
	
	/**
	* 事件绑定-海工
	*/		
	maritimeworks.click(function()
	{
		if(this.checked)
		{
			maritimeworks_trends.attr('checked',true);
			maritimeworks_ordersheet.attr('checked',true);
		}
		else
		{
			maritimeworks_trends.attr('checked',false);
			maritimeworks_ordersheet.attr('checked',false);
		}		
	});	
	
	//事件绑定-子类
	maritimeworks.funcs={};
	maritimeworks.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			maritimeworks.attr('checked','checked');
		}
		else
		{
			var tmp=maritimeworks_trends.attr('checked')!='checked'&&maritimeworks_ordersheet.attr('checked')!='checked';
			if(tmp){
				maritimeworks.attr('checked',false);
			}
		}
	};
	maritimeworks_trends.click(function(){maritimeworks.funcs.callback(maritimeworks_trends)});
	maritimeworks_ordersheet.click(function(){maritimeworks.funcs.callback(maritimeworks_ordersheet)});
	
	/**
	 * 事件绑定-数据
	 */		
	data.click(function()
	{
		if(this.checked)
		{
			data.attr('checked',true);
			data_new.attr('checked',true);
			data_scrap.attr('checked',true);
			data_shipping.attr('checked',true);
			data_steels.attr('checked',true);
			data_second.attr('checked',true);
			data_rent.attr('checked',true);
		}
		else
		{
			data.attr('checked',false);
			data_new.attr('checked',false);
			data_scrap.attr('checked',false);
			data_shipping.attr('checked',false);
			data_steels.attr('checked',false);
			data_second.attr('checked',false);
			data_rent.attr('checked',false);
		}		
	});
	
	//事件绑定-子类
	data.funcs={};
	data.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			data.attr('checked','checked');
		}
		else
		{
			var tmp=data_new.attr('checked')!='checked'&&data_scrap.attr('checked')!='checked';
				tmp=tmp&&data_shipping.attr('checked')!='checked'&&data_steels.attr('checked')!='checked';
				tmp=tmp&&data_second.attr('checked')!='checked'&&data_rent.attr('checked')!='checked';
			if(tmp){
				data.attr('checked',false);
			}
		}
	};
	data_new.click(function(){data.funcs.callback(data_new)});
	data_scrap.click(function(){data.funcs.callback(data_scrap)});
	data_shipping.click(function(){data.funcs.callback(data_shipping)});
	data_steels.click(function(){data.funcs.callback(data_steels)});
	data_second.click(function(){data.funcs.callback(data_second)});
	data_rent.click(function(){data.funcs.callback(data_rent)});
	
	/**
	* 事件绑定-融资
	*/	
	finacing.click(function()
	{
		if(this.checked)
		{
			finacing_policy.attr('checked',true);
			finacing_cooperation.attr('checked',true);
			finacing_trends.attr('checked',true);
			finacing_ipo.attr('checked',true);
		}
		else
		{
			finacing_policy.attr('checked',false);
			finacing_cooperation.attr('checked',false);
			finacing_trends.attr('checked',false);
			finacing_ipo.attr('checked',false);
		}		
	});
	
	//事件绑定-子类
	finacing.funcs={};
	finacing.funcs.callback=function($element)
	{
		if($element.attr('checked')=='checked'){
			finacing.attr('checked','checked');
		}
		else
		{
			var tmp=finacing_policy.attr('checked')!='checked'&&finacing_cooperation.attr('checked')!='checked';
				tmp=tmp&&finacing_trends.attr('checked')!='checked'&&finacing_ipo.attr('checked')!='checked';
			if(tmp){
				finacing.attr('checked',false);
			}
		}
	};
	finacing_policy.click(function(){finacing.funcs.callback(finacing_policy)});
	finacing_cooperation.click(function(){finacing.funcs.callback(finacing_cooperation)});
	finacing_trends.click(function(){finacing.funcs.callback(finacing_trends)});
	finacing_ipo.click(function(){finacing.funcs.callback(finacing_ipo)});
	
	/**
	* 激活控件-提交按钮
	*/
	button_submit.attr('disabled',false);
	button_reset.attr('disabled',false);	
});